﻿using UnityEngine;
public class navi : MonoBehaviour {
    public GameObject gameobject1;
    public bool isNavi;
    public bool isGameStart;
    public GameObject sm1;
    public StateMachine state1;
   // public FirstPersonController fp;

	// Use this for initialization
	void Start () {
        isNavi = true;
        isGameStart = false;
        gameobject1 = GameObject.Find("Sphere1");
        sm1 = GameObject.Find("StateMachine1");
       state1 = sm1.GetComponent<StateMachine>(); 
         
    }
	
	// Update is called once per frame
	void Update () {
        if(isNavi && state1.GameStartState())
            GetComponent<UnityEngine.AI.NavMeshAgent>().destination = gameobject1.transform.position;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.transform.name == "Sphere1")
        {
          //  Destroy(collision.gameObject);
            gameobject1 = GameObject.Find("Sphere2");
        }
        else if (collision.transform.name == "Sphere2")
        {
            //Destroy(collision.gameObject);
            isNavi = false;
        }
    }

    
}
